package com.test.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractWizardFormController;

import com.test.model.UserModel;

public class InfoFillWizardFormController extends AbstractWizardFormController {

	public InfoFillWizardFormController() {
		setCommandClass(UserModel.class);
		setCommandName("user");
		System.out.println("...InfoFillWizardFormController...");
	}

	@Override
	protected Map<String, Object> referenceData(HttpServletRequest request,
			int page) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		if (page == 1) { // 如果是填写学校信息页需要学校类型信息
			map.put("schoolTypeList", Arrays.asList("高中", "中专", "大学"));
		}
		if (page == 2) {// 如果是填写工作信息页需要工作城市信息
			map.put("cityList", Arrays.asList("济南", "北京", "上海"));
		}
		System.out.println("...referenceData...");
		return map;
	}

	@Override
	protected void validatePage(Object command, Errors errors, int page) {
		// 提供每一页数据的验证处理方法
		System.out.println("...validatePage...");
	}

	@Override
	protected void postProcessPage(HttpServletRequest request, Object command,
			Errors errors, int page) throws Exception {
		// 提供每一页完成时的后处理方法
		System.out.println("...postProcessPage...");
	}

	@Override
	protected ModelAndView processFinish(HttpServletRequest req,
			HttpServletResponse resp, Object command, BindException errors)
			throws Exception {
		// 成功后的处理方法
		System.out.println(command);
		System.out.println("...processFinish...");
		return new ModelAndView("redirect:/success");
	}

	@Override
	protected ModelAndView processCancel(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		// 取消后的处理方法
		System.out.println(command);
		System.out.println("...processCancel...");
		return new ModelAndView("redirect:/cancel");
	}

}
